//
//  LSBHelper.m
//  LZZSandboxViewer
//
//  Created by zizheng lu on 2021/10/28.
//

#import "LSBHelper.h"

@implementation LSBHelper


+(void)showAlertWithTitle:(NSString *)title message:(NSString *)message onVc:(UIViewController *)onVc btnTitle:(NSString *)btnTitle leftAction:(void (^)(UIAlertAction * _Nonnull))action
{
    UIAlertController * ac = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    if (btnTitle) {
        [ac addAction:[UIAlertAction actionWithTitle:btnTitle style:UIAlertActionStyleDefault handler:action]];
    }
    [onVc presentViewController:ac animated:YES completion:nil];
}

+(void)showAlertWithTitle:(NSString *)title message:(NSString *)message onVc:(UIViewController *)onVc leftBtnTitle:(NSString *)leftBtnTitle leftAction:(void (^)(UIAlertAction * _Nonnull))leftAction rightBtnTitle:(NSString *)rightBtnTitle rightAction:(void (^)(UIAlertAction * _Nonnull))rightAction
{
    UIAlertController * ac = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    if (leftBtnTitle) {
        [ac addAction:[UIAlertAction actionWithTitle:leftBtnTitle style:UIAlertActionStyleDestructive handler:leftAction]];
    }
    if (rightBtnTitle) {
        [ac addAction:[UIAlertAction actionWithTitle:rightBtnTitle style:UIAlertActionStyleCancel handler:rightAction]];
    }
    [onVc presentViewController:ac animated:YES completion:nil];
}

static NSString * const kLSBResourcesBundleName = @"LSBResources";
static NSBundle * resourceBundle = nil;

+(NSBundle *)getResourceBundle
{
    if (!resourceBundle) {
        NSBundle * mainBundle = [NSBundle bundleForClass:self];
        NSString * resourcePath = [mainBundle pathForResource:kLSBResourcesBundleName ofType:@"bundle"];
        resourceBundle = [NSBundle bundleWithPath:resourcePath] ?: mainBundle;
    }
    return resourceBundle;
}
+(UIImage *)imageWithName:(NSString *)imageName
{

    UIImage * image = [UIImage imageNamed:imageName inBundle:[self getResourceBundle] compatibleWithTraitCollection:nil];
    return image;
}

@end
